﻿@model IList<Reservation>
@*TODO: use a list of models*@
@using HotelRegistrationSystem.DAL

@{
    ViewBag.Title = "UserReservations";
}

<h2>UserReservations</h2>

<table>
    <thead>
        <tr>
            <th>Hotel</th>
            <th>Room</th>
            <th>Beds</th>
            <th>From</th>
            <th>To</th>
            <th>Price</th>
            <th>Status</th>
            <th>Cancel</th>
            <th>Payments</th>
        </tr>
    </thead>
    <tbody>
        @foreach (var reservation in Model)
        {
            <tr>
                <td>
                    @ReservationsDAL.GetHotelNameFromReservation(reservation.ReservationId)
                </td>
                <td>
                    @RoomDAL.GetRoomName(reservation.ReservationId)
                </td>
                <td class="center_td">
                    @ReservationsDAL.GetBedsOfReservation(reservation.ReservationId)
                </td>
                <td>
                    @reservation.StartDate.ToString("dd MMMM yyyy")
                </td>
                <td>
                    @reservation.StartDate.AddDays(reservation.Period).ToString("dd MMMM yyyy")
                </td>
                <td>
                    @ReservationsDAL.GetPriceOfReservation(reservation.ReservationId).ToString("F2")
                </td>
                <td>
                    @reservation.ReservationStatus.StatusName
                </td>
                <td class="center_td">
                    @switch (ReservationsDAL.GetReservationTypeIdFromReservation(reservation.ReservationId))
                    {
                        // TODO: case 1
                        case 3:
                        case 4:
                            if (reservation.ReservationStatusId != 3 && DateTime.Now < reservation.StartDate.AddDays(-2))
                            {
                                using(@Html.BeginForm(new RouteValueDictionary(new { reservationId = reservation.ReservationId })))
                                {
                                    <input type="submit" class="button small radius" value="Cancel" />
                                }                         
                            }
                            else
                            {
                                <text>X</text>
                            }
                            break;
                        default:
                            <text>X</text>
                            break;
                    }
                </td>
                <td>
                    @if(reservation.ReservationStatusId == 1 ||
                        reservation.ReservationStatusId == 1) 
                    {
                        var paymentModel = new HotelRegistrationSystem.Models.PaymentModel(
                            reservation.ReservationId, 
                            ReservationsDAL.GetPriceOfReservation(reservation.ReservationId)
                        );
                        @Html.Partial("_PaymentButton", paymentModel)
                    }
                </td>
            </tr>
        }
    </tbody>
</table>
